<%
    /**
     * 单条字典项json定义
     */
    def dictDefineJson = {dict, formatPrepend ->
        def dictRuleList =new ArrayList();
        def optionList = dict.optionList;
        optionList.eachWithIndex { option, index ->
            def cssType = option['cssClass'];
            if(cssType == null || cssType == ''){
                cssType = 'default';
            }
            def dictItem = new HashMap();
            dictItem["kind"] = dict.id;
            dictItem["itemKey"] = option.value;
            dictItem["itemName"] = option.name;
            dictItem["sortNum"] = index+1;
            dictItem["cssType"] = cssType;
            dictRuleList.add(dictItem)
        }
        return dictRuleList;
    }

    /**
     * 整个表模型的字典项定义
     */
    def tableModelDictDefineJson = { tableModel, formatPrepend ->
        if (formatPrepend == null) {
            formatPrepend = '';
        }
        def dictMap = tableModel['dictMap']
        if (dictMap == null || dictMap.isEmpty()) {
            return "{}"
        }

        def dictRuleMap = [:]
        dictMap.each { key, dict ->
            def oneDictDefine = dictDefineJson(dict, formatPrepend);
            dictRuleMap.put(key, oneDictDefine);
        }
        return JSON.toJSONString(dictRuleMap,
                com.alibaba.fastjson.serializer.SerializerFeature.PrettyFormat,
                com.alibaba.fastjson.serializer.SerializerFeature.UseSingleQuotes);
    }

    customTool['tableModelDictDefineJson'] = tableModelDictDefineJson;




    def formRuleDefineJson ={column ->
        def isMust=(column.canBeNull==false);
        def handler="string";
        if("INT".equalsIgnoreCase(column.columnType) ||"INTEGER".equalsIgnoreCase(column.columnType) ||"BIGINT".equalsIgnoreCase(column.columnType)||
                "TINYINT".equalsIgnoreCase(column.columnType)||"SMALLINT".equalsIgnoreCase(column.columnType)){
            handler="integer";
        }else if("DOUBLE".equalsIgnoreCase(column.columnType) ||"DECIMAL".equalsIgnoreCase(column.columnType)  ||"FLOAT".equalsIgnoreCase(column.columnType)){
            handler="float";
        }

        def defineArray = [];
        defineArray.add(column.dataName);

        def rules = [];
        def ruleMap = [:]
        ruleMap["required"]= isMust;
        def message = """${column.cnname}不能为空""";
        ruleMap["message"]= message.toString();
        //ruleMap["type"] = handler;
        rules.add(ruleMap);
        defineArray.add(["rules": rules]);
        return JSON.toJSONString(defineArray,
                com.alibaba.fastjson.serializer.SerializerFeature.UseSingleQuotes);
    }
    customTool['formRuleDefineJson'] = formRuleDefineJson;

%>